
var mongoose = require('mongoose');
mongoose.Promise = Promise;
mongoose.connect('mongodb://dev1.bjvca.com:27017/test2');

var UserSchema = new mongoose.Schema({
    blog:{
        type:String,
        get:function(url){
            if(!url) return url;

            if(0 !== url.indexOf('http://')&&0 !==url.indexOf('https://'))
                url='http://'+url;
            console.log("url:"+url);
            return url;
        }
    }
})


UserSchema.set('toObject',{getter:true,virtual:true});

var User = mongoose.Schema('User',UserSchema);



var user = new User({
    blog:'baidu.com'
});

user.save(function(err){
    if(err){
        console.log("save error:"+err);
        // return;
    }

    console.log(user);
});
